<template>
  <view>
    <view class="album_bg">
      <image mode="widthFix" :src="album.cover"></image>
      <view class="album_info">
        <view class="album_name">{{ album.name }}</view>
        <view class="album_btn">关注专辑</view>
      </view>
    </view>
    <view class="album_author">
      <view class="album_author_info">
        <image mode="widthFix" :src="album.user.avatar"></image>
        <view class="author_name">{{ album.user.name }}</view>
      </view>
      <view class="album_author_desc">
        <text>{{ album.desc }}</text>
      </view>
    </view>
    <view class="album_list">
      <view
        class="album_item"
        v-for="(item, index) in wallpaper"
        :key="item.id"
      >
        <go-detail :list="wallpaper" :index="index">
          <image
            mode="aspectFill"
            :src="item.thumb + item.rule.replace('$<Height>', 360)"
          ></image>
        </go-detail>
      </view>
    </view>
  </view>
</template>

<script>
import goDetail from "@/components/goDatil";
export default {
  components: {
    goDetail,
  },
  data() {
    return {
      params: {
        limit: 30,
        order: "new",
        skip: 0,
        first: 1,
      },
      id: -1,
      album: {},
      wallpaper: [],
      hasMore: true,
    };
  },
  onLoad(options) {
    this.id = options.id;
    // this.id = "5d5f8e45e7bce75ae7fb8278";
    this.getList();
  },
  onReachBottom() {
    if (this.hasMore) {
      this.params.first = 0;
      this.params.skip += this.params.limit;
      this.getList();
    } else {
      uni.showToast({
        title: "已是最后一页",
        icon: "none",
      });
    }
  },
  methods: {
    getList() {
      this.request({
        url: `http://157.122.54.189:9088/image/v1/wallpaper/album/${this.id}/wallpaper`,
        data: this.params,
      }).then((res) => {
        //this.album是对象不是数组，无法直接表示长度，Object.keys（）表示判断是否是对象，如果是，则返回数组类型
        if (Object.keys(this.album).length === 0) {
          this.album = res.res.album;
        }

        if (res.res.wallpaper.length === 0) {
          this.hasMore = false;
          uni.showToast({
            title: "已是最后一页",
            icon: "none",
          });
          return;
        }
        this.wallpaper = [...this.wallpaper, ...res.res.wallpaper];
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.album_bg {
  position: relative;
  .album_info {
    padding: 0 15rpx;
    position: absolute;
    display: flex;
    justify-content: space-between;
    width: 100%;
    bottom: 25rpx;
    left: 0;
    color: #fff;
    .album_name {
      font-size: 34rpx;
    }
    .album_btn {
      width: 152rpx;
      height: 60rpx;
      background-color: #d52a7e;
      border-radius: 10rpx;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}

.album_author {
  padding: 10rpx;
  .album_author_info {
    padding: 10rpx;
    display: flex;
    image {
      width: 50rpx;
    }

    .author_name {
      margin-left: 20rpx;
      color: #000;
      font-weight: 600;
    }
  }
}

.album_list {
  display: flex;
  flex-wrap: wrap;
  padding: 10rpx;
  .album_item {
    width: 33.33%;
    border: 3rpx solid #fff;
    image{
      height: 160rpx;
    }
  }
}
</style>